package com.LeeCode;

/**
 * 移除链表元素
 */

public class Code203 {
    public static void main(String[] args) {
        int[] arr = {7, 7, 7, 7};
        ListNode head = Utils.arrayToListNode(arr);
        Utils.printListNode(new Code203().removeElements(head, 7));
    }

    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyHead = new ListNode(0, head);
        ListNode cur = dummyHead;
        while (cur.next != null) {
            if (cur.next.val == val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return dummyHead.next;
    }
}
